home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Demos / Bowers Development / AppMaker 2.1.sit / AppMaker 2.1 / Examples / Procedural / AMReminder / MainWindow.c / MainWindow.c
Encoding:
C/C++ Source or Header  |  1997-07-01  |  5.9 KB  |  265 lines  |  [TEXT/CWIE]

  1. /* MainWindow.c */
  2. /* Created 6/10/97 12:23 PM by AppMaker */
  3.  
  4. #include <Types.h>
  5. #include <Quickdraw.h>
  6. #include <Controls.h>
  7. #include <Dialogs.h>
  8. #include <Events.h>
  9. #include <Lists.h>
  10. #include <Menus.h>
  11. #include <Resources.h>
  12. #include <TextEdit.h>
  13. #include <ToolUtils.h>
  14. #include "ResourceDefs.h"
  15. #include "Globals.h"
  16. #include "Miscellany.h"
  17. #include "Scrolling.h"
  18. #include "WindowAids.h"
  19. #include "AMReminderData.h"
  20. #include "Add.h"
  21. #include "MainWindow.h"
  22.  
  23.  
  24. #define LogoPicture        1
  25. #define YearLabel        2
  26. #define RemindersLabelLabel        3
  27. #define RemindersList        4
  28. #define AddButton        5
  29. #define Add2Button        6
  30. #define DeleteButton        7
  31.  
  32. static void BuildRemindersList    (void);
  33. static void DoAddButton (void);
  34. static void DoAdd2Button (void);
  35. static void DoDeleteButton (void);
  36.  
  37. /*----------*/
  38. static void BuildRemindersList    ()
  39. {
  40.     Rect            bounds;
  41.  
  42.     SetWFont (RemindersList);
  43.     GetWRect (RemindersList, &bounds);
  44.     cur->RemindersHandle = NewV1List (bounds, qd.thePort);
  45.     AddToList ("\pOne",   cur->RemindersHandle);
  46.     AddToList ("\pTwo",   cur->RemindersHandle);
  47.     AddToList ("\pThree", cur->RemindersHandle);
  48.     AddToList ("\pInfinity",  cur->RemindersHandle);
  49.     LSetDrawingMode (true, cur->RemindersHandle);
  50.  
  51. } /*BuildRemindersList*/
  52.  
  53. /*----------*/
  54. static void DoAddButton ()
  55. {
  56.     AddRec                AddInfo;
  57.     register AddRecPtr    info;
  58.  
  59.     info = &AddInfo;
  60.     /*initialize Add info*/
  61.     info->LogoData = nil;
  62.     info->Date2Text [0] = 0;
  63.     info->Time2Text [0] = 0;
  64.     info->AmPmChoice = 1;
  65.     info->Message2Text [0] = 0;
  66.     info->DisplayIconChecked = false;
  67.     info->DisplayAlertChecked = false;
  68.     info->PlaySoundChecked = false;
  69.     info->SoundChoice = 1;
  70.  
  71.     if (GetAdd (&AddInfo)) {
  72.         /*use Add info*/
  73.     }
  74. } /*DoAddButton*/
  75.  
  76. /*----------*/
  77. static void DoAdd2Button ()
  78. {
  79.     AddRec                AddInfo;
  80.     register AddRecPtr    info;
  81.  
  82.     info = &AddInfo;
  83.     /*initialize Add info*/
  84.     info->LogoData = nil;
  85.     info->Date2Text [0] = 0;
  86.     info->Time2Text [0] = 0;
  87.     info->AmPmChoice = 1;
  88.     info->Message2Text [0] = 0;
  89.     info->DisplayIconChecked = false;
  90.     info->DisplayAlertChecked = false;
  91.     info->PlaySoundChecked = false;
  92.     info->SoundChoice = 1;
  93.  
  94.     if (GetAdd (&AddInfo)) {
  95.         /*use Add info*/
  96.     }
  97. } /*DoAdd2Button*/
  98.  
  99. /*----------*/
  100. static void DoDeleteButton ()
  101. {
  102. } /*DoDeleteButton*/
  103.  
  104. /*----------*/
  105. void OpenMainWindow    (FSSpec*    fileSpec,
  106.                          short        fRefNum)
  107. {
  108.     WindowPtr        newWindow;
  109.     Rect            bounds;
  110.  
  111.     newWindow = GetWindow (WIND_MainWindow);
  112.     if (fileSpec->name [0] != 0) {
  113.         SetWTitle (newWindow, fileSpec->name);
  114.     }
  115.     SetPort (newWindow);
  116.     SetNewInfo (newWindow);
  117.     cur->vScroll = nil;
  118.     cur->hScroll = nil;
  119.     cur->fileNum    = fRefNum;
  120.     cur->dirty        = false;
  121.     cur->filename    = NewString (fileSpec->name);
  122.     cur->windowKind = WMainWindow;
  123.     ((WindowPeek) curWindow)->windowKind = userKind + WMainWindow;
  124.     cur->witlHandle = GetResource ('Witl', WIND_MainWindow);
  125.     cur->wictHandle = GetResource ('Wict', WIND_MainWindow);
  126.  
  127.     BuildRemindersList ();
  128.     cur->AddHandle = GetNewControl (CNTL_Add, newWindow);
  129.     cur->Add2Handle = GetNewControl (CNTL_Add2, newWindow);
  130.     cur->DeleteHandle = GetNewControl (CNTL_Delete, newWindow);
  131.  
  132.     cur->text = nil;
  133.     ShowWindow (newWindow);
  134. } /*OpenMainWindow*/
  135.  
  136. /*----------*/
  137. void CloseMainWindow    (void)
  138. {
  139.         LDispose (cur->RemindersHandle);
  140.  
  141.     DisposeHandle ((Handle) cur->filename);
  142.     DiscardInfo (curWindow);
  143. } /*CloseMainWindow*/
  144.  
  145. /*----------*/
  146. void ControlMainWindow  (ControlHandle        whichControl,
  147.                          short                whichPart,
  148.                          Point                where)
  149. {
  150.     Rect            bounds;
  151.  
  152.     if ((whichControl == (**(cur->RemindersHandle)).vScroll)
  153.     ||  (whichControl == (**(cur->RemindersHandle)).hScroll)) {
  154.         if (LClick (where, 0, cur->RemindersHandle)) {
  155.             /*double click in scroll bar*/
  156.         }
  157.     }
  158.     if (whichControl == cur->AddHandle) {
  159.         if (TrackButton (cur->AddHandle, where)) {
  160.             DoAddButton ();
  161.         }
  162.     }
  163.     if (whichControl == cur->Add2Handle) {
  164.         if (TrackButton (cur->Add2Handle, where)) {
  165.             DoAdd2Button ();
  166.         }
  167.     }
  168.     if (whichControl == cur->DeleteHandle) {
  169.         if (TrackButton (cur->DeleteHandle, where)) {
  170.             DoDeleteButton ();
  171.         }
  172.     }
  173.  
  174. } /*ControlMainWindow*/
  175.  
  176. /*----------*/
  177. void MouseInMainWindow    (Point        where,
  178.                          short        modifiers)
  179. {
  180.     Rect            bounds;
  181.  
  182.     if (PtInRect (where, &(**(cur->RemindersHandle)).rView)) {
  183.         if (LClick (where, modifiers, cur->RemindersHandle)) {
  184.             /*double click*/
  185.         }
  186.         if (GetListChoice (&cur->RemindersChoice, cur->RemindersHandle)) {
  187.             /* something is selected */
  188.         }
  189.     }
  190.  
  191. } /*MouseInMainWindow*/
  192.  
  193. /*----------*/
  194. void TypeInMainWindow   (char        ch)
  195. {
  196.     if ((ch == charEnter)
  197.     ||  (ch == charReturn)) {
  198.         SimulateClick (cur->AddHandle);
  199.         DoAddButton ();
  200.     } else if (ch == charEsc) {
  201.     } else if (ch == charTab) {
  202.         /* tab among edit fields */
  203.     } else if (cur->text == nil) {
  204.         SysBeep (1);
  205.     } else {
  206.         TEKey (ch, cur->text);
  207.         cur->dirty = true;
  208.     }
  209. } /*TypeInMainWindow*/
  210.  
  211. /*----------*/
  212. void UpdateMainWindow (void)
  213. {
  214.     Rect            bounds;
  215.  
  216.     GetWRect (LogoPicture, &bounds);
  217.     DrawPictureID (PICT_Logo, bounds);
  218.  
  219.     SetWFont (YearLabel);
  220.     GetWRect (YearLabel, &bounds);
  221.     TextIDBox (TEXT_Year, bounds);
  222.  
  223.     SetWFont (RemindersLabelLabel);
  224.     GetWRect (RemindersLabelLabel, &bounds);
  225.     TextIDBox (TEXT_RemindersLabel, bounds);
  226.  
  227.     SetWFont (RemindersList);
  228.     LUpdate (qd.thePort->visRgn, cur->RemindersHandle);
  229.     bounds = (**(cur->RemindersHandle)).rView;
  230.     InsetRect (&bounds, -1, -1);
  231.     FrameRect (&bounds);
  232.     SetWFont (AddButton);
  233.     Draw1Control (cur->AddHandle);
  234.     OutlineButtonRect ((**(cur->AddHandle)).contrlRect);
  235.     SetWFont (Add2Button);
  236.     Draw1Control (cur->Add2Handle);
  237.     SetWFont (DeleteButton);
  238.     Draw1Control (cur->DeleteHandle);
  239. } /*UpdateMainWindow*/
  240.  
  241. /*----------*/
  242. void ActivateMainWindow    (Boolean    activate)
  243. {
  244.     LActivate (activate, cur->RemindersHandle);
  245.  
  246. } /*ActivateMainWindow*/
  247.  
  248. /*----------*/
  249. void ResizeMainWindow    (void)
  250. {
  251.     /* application-specific code to resize items in window */
  252. } /*ResizeMainWindow*/
  253.  
  254. /*----------*/
  255. pascal void ScrollMainWindow    (short        newValue,
  256.                                  short        oldValue)
  257. {
  258.     /* application-specific code to scroll window */
  259.     if (gWhichScroll == cur->vScroll) {
  260.     } else {    // horizontal
  261.     }
  262. } /*ScrollMainWindow*/
  263.  
  264. /* MainWindow */
  265.